package com.yida.wy.vote.outside.controller;

import cn.hutool.core.bean.BeanUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.wy.common.valid.CancelSelect;
import com.yida.wy.common.valid.ConfirmSelect;
import com.yida.wy.vote.outside.domain.request.WyVoteHouseQueryRequest;
import com.yida.wy.vote.outside.domain.request.WyVoteHouseSelectRequest;
import com.yida.wy.vote.outside.domain.WyVoteHouse;
import com.yida.wy.vote.outside.service.IWyVoteHouseService;
import com.yida.wy.vote.outside.service.IWyVoteProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 投票房屋Controller
 *
 * @author lqq
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/house")
@Api(tags = "投票房屋")
public class WyVoteHouseController extends BaseController {

	@Resource
	private IWyVoteProjectService voteProjectService;

	@Resource
	private IWyVoteHouseService voteHouseService;

	@ApiOperation("根据条件查询房屋信息")
	@PostMapping("/houseInfo")
	public TableDataInfo houseInfo(@Validated @RequestBody WyVoteHouseQueryRequest request) {
		startPage();
		List<WyVoteHouse> list = voteHouseService.selectVoteHouseList(BeanUtil.copyProperties(request, WyVoteHouse.class));
		return getDataTable(list);
	}

	@ApiOperation("加入选择")
	@RequiresPermissions("gwj:vote:outside:e:project:add")
	@PostMapping("/confirmSelect")
	@Log(title = "公维金外网投票-房屋加入选择", businessType = BusinessType.INSERT, systemName = "vote")
	public AjaxResult confirmSelect(@Validated(ConfirmSelect.class) @RequestBody WyVoteHouseSelectRequest request) {
		return toAjax(voteProjectService.confirmSelectHouse(request.getVoteHouseIds(), request.getVoteId()));
	}

	@ApiOperation("取消选择")
	@RequiresPermissions("gwj:vote:outside:e:project:add")
	@PostMapping("/cancelSelect")
	@Log(title = "公维金外网投票-房屋取消选择", businessType = BusinessType.DELETE, systemName = "vote")
	public AjaxResult cancelSelect(@Validated(CancelSelect.class) @RequestBody WyVoteHouseSelectRequest request) {
		return toAjax(voteProjectService.cancelSelectHouse(request.getVoteHouseIds(), request.getVoteId()));
	}
}
